package com.sservice.commonBusiness.controller.admin;

import com.sservice.commonBusiness.e.PLetter;
import com.sservice.commonBusiness.service.PLetterService;
import com.sservice.commonBusiness.vo.PLetterVo;
import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * Created by byte_su@163.com on 2018/01/12.
 */
@Controller
@RequestMapping("/admin/pLetter/")
public class PLetterController {

    @Autowired
    PLetterService pLetterService;

    @RequestMapping(value="add",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult add(PLetter pLetter) {
        return new BaseResult(true,String.valueOf(pLetterService.insertSelective(pLetter)),200);
    }

    @RequestMapping(value="delete/{id}",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult delete(PLetter pLetter) {
        return new BaseResult(true,String.valueOf(pLetterService.deleteByPrimaryKey(pLetter.getId())),200);
    }

    @RequestMapping(value="update",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult update(PLetter pLetter) {
        return new BaseResult(true,String.valueOf(pLetterService.updateByPrimaryKeySelective(pLetter)),200);
    }

    @RequestMapping("detail/{id}")
    @ResponseBody
    public BaseResult detail(@RequestParam Integer id) {
        PLetter pLetter = pLetterService.selectByPrimaryKey(id);
        return new BaseResult(true,pLetter);
    }

    @RequestMapping("list")
    @ResponseBody
    public ListResult list(PLetterVo page) {
        return pLetterService.page(page);
    }
    @RequestMapping("count")
    @ResponseBody
    public BaseResult count(PLetterVo page) {
        int list = pLetterService.queryCount(page);
        return new BaseResult(true, list);
    }
}
